package com.yuerlive.rainbow.module.game.presenter;

import com.yuerlive.rainbow.api.LiveApi;
import com.yuerlive.rainbow.api.LiveService;
import com.yuerlive.rainbow.base.BasePresenterImpl;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.GameInfo;
import com.yuerlive.rainbow.entity.NiuniuHistory;
import com.yuerlive.rainbow.rx.RxHelper;
import com.yuerlive.rainbow.rx.RxObserver;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoyi on 2017/6/15.
 */

public class GamePresenter extends BasePresenterImpl implements GameContract.Presenter {
    private GameContract.View view;
    private LiveService liveService;

    public GamePresenter(GameContract.View view) {
        this.view = view;
        this.view.setPresenter(this);
        this.liveService = LiveApi.getInstance().liveService;
    }

    @Override
    public void getGameHistory(String liveId,String gameID) {
        Map<String, String> params = new HashMap<>();
        params.put("liveId", liveId);
        params.put("gameId", gameID);
        liveService.getNiuniuHistory(params)
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<List<NiuniuHistory>>>(this) {
                    @Override
                    protected void onSuccess(BaseData<List<NiuniuHistory>> listBaseData) {
                        view.showHistoryResult(listBaseData);
                    }

                    @Override
                    protected void onFail(String message) {

                    }
                });
    }

    @Override
    public void getGameInfo(String gameId) {
        Map<String,String > params  = new HashMap<>();
        params.put("gameId",gameId);
        liveService.getGameInfo(params).compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<GameInfo>>(this) {
                    @Override
                    protected void onSuccess(BaseData<GameInfo> baseData) {
                        view.setGameInfo(baseData.getObject());
                    }

                    @Override
                    protected void onFail(String message) {

                    }
                });
    }


}
